import 'package:dmz/base/controller/base_controller.dart';
import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/base/widget/keep_alive_wrapper.dart';
import 'package:dmz/business/find/controller/find_main_controller.dart';
import 'package:dmz/business/find/page/find_main_page.dart';
import 'package:dmz/business/home/controller/home_main_controller.dart';
import 'package:dmz/business/home/controller/home_page_ctcs.dart';
import 'package:dmz/business/home/page/home_main_page.dart';
import 'package:dmz/business/home/widgets/bottom_bar.dart';
import 'package:dmz/business/mine/controller/mine_main_controller.dart';
import 'package:dmz/business/mine/page/mine_main_page.dart';
// import 'package:dmz/business/mine/page/mine_main_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MainPage extends BaseStatefulWidget<MainController> {
  const MainPage({super.key});

  @override
  bool showTitleBar() => false;

  @override
  Widget buildContent(BuildContext context) {
    return Stack(children: [
      Container(
        decoration: const BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter, // 渐变起始位置
              end: Alignment.bottomCenter, // 渐变结束位置
              colors: [Color(0xFF131317), Color(0xFF2C2D35)], // 渐变色数组
            ),
            image: DecorationImage(
                image: AssetImage('assets/images/home/main/home_back.png'),
                fit: BoxFit.fill)),
      ),
      Scaffold(
          drawerScrimColor: Colors.transparent,
          backgroundColor: Colors.transparent,
          body: KeepAliveWrapper(
            child: PageView(
              controller: controller.pageController,
              physics: const NeverScrollableScrollPhysics(),
              children: controller.naviItems,
            ),
          ),
          bottomNavigationBar: SizeTransition(
              sizeFactor: controller.animationController,
              axisAlignment: -1.0,
              child: Obx(() => BottomBarWidget(
                  selectIndex: controller.curPage.value,
                  itemClick: controller.itemClick))))
    ]);
  }
}

class MainController extends BaseController
    with GetSingleTickerProviderStateMixin {
  DateTime? lastPopTime;
  final RxInt curPage = 0.obs;

  final PageController pageController = PageController(initialPage: 0);

  late AnimationController animationController;
  bool hideBottomNavBar = false;

  final List<Widget> naviItems = [
    const HomePage(),
    const FindPage(),
    // const HomePagecs()
    const MinePage()
  ];

  @override
  void loadNet() {}

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onInit() {
    animationController = AnimationController(
      duration: const Duration(milliseconds: 200),
      vsync: this,
    );
    super.onInit();
  }

  @override
  void onHidden() {}

  ///导航栏收缩
  void bottomAction() {
    hideBottomNavBar = !hideBottomNavBar;
    if (hideBottomNavBar) {
      animationController.forward();
    } else {
      animationController.reverse();
    }
  }

  void itemClick(int index) {
    curPage.value = index;
    pageController.jumpToPage(index);
  }
}

class MainBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => MainController());
    Get.lazyPut(() => FindPageController());
    Get.lazyPut(() => HomePageController());
    Get.lazyPut(() => MinePageController());
    Get.lazyPut(() => HomePageControllercs());
  }
}
